#!/usr/bin/python
#coding:utf8
'''
Observer
'''
# 职位公告
class JobPost:
    def __init__(self, title):
        self.title = title
    def getTitle(self):
        return self.title

# 观察者
class JobSeeker:
    def __init__(self, name):
        self.name = name
    # 当有新的职位公告时，调用此方法
    def onJobPosted(self, job):
        print(f'{self.name} got a new job post: {job.getTitle()}')

# 职位发布者（被观察）
class EmploymentAgency:
    def __init__(self):
        # 作为演示，没有构建职业池存储招聘岗位
        self.job_seekers = []
    # 求职者订阅后，添加进求职者池
    def addJobSeeker(self, job_seeker):
        self.job_seekers.append(job_seeker)
    def detachJobSeeker(self, job_seeker):
        self.job_seekers.remove(job_seeker)
    def postJob(self, job):
        for job_seeker in self.job_seekers:
            job_seeker.onJobPosted(job)
    def addJob(self, job):
        self.postJob(job)

if __name__ == '__main__':
    zhangsan = JobSeeker('zhangsan')
    lisi = JobSeeker('lisi')
    agency = EmploymentAgency()
    agency.addJobSeeker(zhangsan)
    agency.addJobSeeker(lisi)
    agency.addJob(JobPost('Python Developer'))

